#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "Element.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class ExecutableNode;
class OutputPin;

/// <summary>
/// Clause
/// A Clause is an Element that represents a single branch of a ConditionalNode,
/// including a test and a body section. The body section is executed only if (but
/// not necessarily if) the test section evaluates to true.
/// </summary>
class UMLMODEL_EXPORT Clause : public Element {

public: // Constructors and destructors
    explicit Clause(const QString& umlType="uml::Clause");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Properties
    /// <summary>
    /// bodys getter
    /// The set of ExecutableNodes that are executed if the test evaluates to true and
    /// the Clause is chosen over other Clauses within the ConditionalNode that also
    /// have tests that evaluate to true.
    /// </summary>
    vector<shared_ptr<ExecutableNode>>& bodys();

    /// <summary>
    /// bodyOutputs getter
    /// The OutputPins on Actions within the body section whose values are moved to the
    /// result OutputPins of the containing ConditionalNode after execution of the body.
    /// </summary>
    vector<shared_ptr<OutputPin>>& bodyOutputs();

    /// <summary>
    /// decider getter
    /// An OutputPin on an Action in the test section whose Boolean value determines the
    /// result of the test.
    /// </summary>
    shared_ptr<OutputPin> decider() const;

    /// <summary>
    /// decider setter
    /// An OutputPin on an Action in the test section whose Boolean value determines the
    /// result of the test.
    /// </summary>
    void setDecider(shared_ptr<OutputPin> value);

    /// <summary>
    /// predecessorClauses getter
    /// A set of Clauses whose tests must all evaluate to false before this Clause can
    /// evaluate its test.
    /// </summary>
    vector<shared_ptr<Clause>>& predecessorClauses();

    /// <summary>
    /// successorClauses getter
    /// A set of Clauses that may not evaluate their tests unless the test for this
    /// Clause evaluates to false.
    /// </summary>
    vector<shared_ptr<Clause>>& successorClauses();

    /// <summary>
    /// tests getter
    /// The set of ExecutableNodes that are executed in order to provide a test result
    /// for the Clause.
    /// </summary>
    vector<shared_ptr<ExecutableNode>>& tests();

private: // Fields
    /// <summary>
    /// bodys
    /// The set of ExecutableNodes that are executed if the test evaluates to true and
    /// the Clause is chosen over other Clauses within the ConditionalNode that also
    /// have tests that evaluate to true.
    /// </summary>
    vector<shared_ptr<ExecutableNode>> bodys_;

    /// <summary>
    /// bodyOutputs
    /// The OutputPins on Actions within the body section whose values are moved to the
    /// result OutputPins of the containing ConditionalNode after execution of the body.
    /// </summary>
    vector<shared_ptr<OutputPin>> bodyOutputs_;

    /// <summary>
    /// decider
    /// An OutputPin on an Action in the test section whose Boolean value determines the
    /// result of the test.
    /// </summary>
    shared_ptr<OutputPin> decider_;

    /// <summary>
    /// predecessorClauses
    /// A set of Clauses whose tests must all evaluate to false before this Clause can
    /// evaluate its test.
    /// </summary>
    vector<shared_ptr<Clause>> predecessorClauses_;

    /// <summary>
    /// successorClauses
    /// A set of Clauses that may not evaluate their tests unless the test for this
    /// Clause evaluates to false.
    /// </summary>
    vector<shared_ptr<Clause>> successorClauses_;

    /// <summary>
    /// tests
    /// The set of ExecutableNodes that are executed in order to provide a test result
    /// for the Clause.
    /// </summary>
    vector<shared_ptr<ExecutableNode>> tests_;

};

} // namespace uml
